from sqlalchemy import Column, Integer, String, Boolean, DateTime, func, ForeignKey
from sqlalchemy.orm import relationship
from database import Base
from model.cname_node import cname_node

class CName(Base):
    __tablename__ = "t_cname"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    domain = Column(String(255), nullable=False, unique=True, comment="域名")
    ttl = Column(Integer, default=30, comment="缓存时间")
    status = Column(Boolean, default=False, comment="是否启用")
    created_at = Column(DateTime(timezone=True), server_default=func.now(), comment="创建时间")
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), comment="更新时间")


    nodes = relationship(
        "CdnNode",
        secondary=cname_node,
        back_populates="cnames"
    )
